package cn.t12.qg.goodsprovider.service;

import cn.t12.qg.goodsprovider.mapper.QgGoodsTempStockMapper;
import cn.t12.qg.service.user.GoodsTempStockService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qg.pojo.QgGoodsTempStock;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;
import java.util.Map;

@DubboService(version = "1.0.0",interfaceClass = GoodsTempStockService.class)
public class QgGoodsTempStockServiceImpl implements GoodsTempStockService {

    @Resource
    private QgGoodsTempStockMapper tempStockMapper;

    @Override
    public int countBy(Map<String, Object> map) {
        QueryWrapper<QgGoodsTempStock> wrapper = new QueryWrapper<>();
        wrapper.eq("status",map.get("locked"))
                .or()
                .eq("status",map.get("success"));
        return tempStockMapper.selectCount(wrapper);
    }

    @Override
    public Boolean exists(String userId, String goodsId) {
        QueryWrapper<QgGoodsTempStock> wrapper = new QueryWrapper<>();
        wrapper.eq("goods_id",goodsId)
                .eq("user_id",userId)
                .in("status",0,1);
        return tempStockMapper.selectCount(wrapper)>0;
    }

    @Override
    public int insert(QgGoodsTempStock qgGoodsTempStock) {
        return tempStockMapper.insert(qgGoodsTempStock);
    }
}
